package com.dankegongyu.component.jsbridge.config;

import androidx.annotation.Keep;


import com.dankegongyu.component.jsbridge.listener.DKWebCallback;
import com.dankegongyu.component.jsbridge.listener.DKWebChromeClientCallback;
import com.dankegongyu.component.jsbridge.listener.DKWebDownloadListener;
import com.dankegongyu.component.jsbridge.listener.DKWebJsPlugin;
import com.dankegongyu.component.jsbridge.listener.DKWebSensorsCallback;
import com.dankegongyu.component.jsbridge.listener.DKWebViewClientCallback;
import com.dankegongyu.component.jsbridge.listener.DKWebViewMenuCallback;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by Admin on 2018/3/31.
 */
@Keep
public class DKWebConfig implements Serializable {

    private DKWebToolbarConfig toolbar;

    private String url;
    private String nextUrl;
    private DKWebCallback webCallback;
    private DKWebChromeClientCallback chromeCallback;
    private DKWebViewClientCallback clientCallback;
    private DKWebSensorsCallback sensorsCallback;
    private DKWebViewMenuCallback menuCallback;
    private List<DKWebJsPlugin> mJsPlugins;
    private DKWebDownloadListener mDownloadListener;
    private Map<String, String> headers;
    private String userAgent;
    private boolean isUserAgentAppend;
    private boolean isJsEnabled;
    private boolean isSupportZoom;
    private boolean isBuiltInZoomControls;
    private boolean isUseWideViewPort;
    private boolean isLoadWithOverviewMode;
    private boolean isJavaScriptCanOpenWindowsAutomatically;
    private boolean isAllowFileAccess;
    private boolean isAppCacheEnabled;
    private boolean isDatabaseEnabled;
    private boolean isDomStorageEnabled;
    private boolean isGeolocationEnabled;
    private boolean cacheMode;
    private boolean isAllowContentAccess;
    private boolean isSavePassword;
    private boolean isSaveFormData;

    private DKWebConfig(Builder builder) {
        this.url = builder.url;
        this.toolbar = builder.toolbar;
        this.nextUrl = builder.nextUrl;
        this.webCallback = builder.webCallback;
        this.chromeCallback = builder.chromeCallback;
        this.clientCallback = builder.clientCallback;
        this.sensorsCallback = builder.sensorsCallback;
        this.menuCallback = builder.menuCallback;
        this.mJsPlugins = builder.mJsPlugins;
        this.mDownloadListener = builder.mDownloadListener;
        this.headers = builder.headers;
        this.userAgent = builder.userAgent;
        this.isUserAgentAppend = builder.isUserAgentAppend;
        this.isJsEnabled = builder.isJsEnabled;
        this.isSupportZoom = builder.isSupportZoom;
        this.isBuiltInZoomControls = builder.isBuiltInZoomControls;
        this.isUseWideViewPort = builder.isUseWideViewPort;
        this.isLoadWithOverviewMode = builder.isLoadWithOverviewMode;
        this.isJavaScriptCanOpenWindowsAutomatically = builder.isJavaScriptCanOpenWindowsAutomatically;
        this.isAllowFileAccess = builder.isAllowFileAccess;
        this.isAppCacheEnabled = builder.isAppCacheEnabled;
        this.isDatabaseEnabled = builder.isDatabaseEnabled;
        this.isDomStorageEnabled = builder.isDomStorageEnabled;
        this.isGeolocationEnabled = builder.isGeolocationEnabled;
        this.cacheMode = builder.cacheMode;
        this.isAllowContentAccess = builder.isAllowContentAccess;
        this.isSavePassword = builder.isSavePassword;
        this.isSaveFormData = builder.isSaveFormData;
    }


    public String getUrl() {
        return url;
    }

    public DKWebToolbarConfig getToolbar() {
        return toolbar;
    }

    public String getNextUrl() {
        return nextUrl;
    }

    public DKWebCallback getWebCallback() {
        return webCallback;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public boolean isJsEnabled() {
        return isJsEnabled;
    }

    public boolean isSupportZoom() {
        return isSupportZoom;
    }

    public boolean isBuiltInZoomControls() {
        return isBuiltInZoomControls;
    }

    public boolean isUseWideViewPort() {
        return isUseWideViewPort;
    }

    public boolean isLoadWithOverviewMode() {
        return isLoadWithOverviewMode;
    }

    public boolean isJavaScriptCanOpenWindowsAutomatically() {
        return isJavaScriptCanOpenWindowsAutomatically;
    }

    public boolean isAllowFileAccess() {
        return isAllowFileAccess;
    }

    public boolean isAppCacheEnabled() {
        return isAppCacheEnabled;
    }

    public boolean isDatabaseEnabled() {
        return isDatabaseEnabled;
    }

    public boolean isDomStorageEnabled() {
        return isDomStorageEnabled;
    }

    public boolean isGeolocationEnabled() {
        return isGeolocationEnabled;
    }

    public boolean isCacheMode() {
        return cacheMode;
    }

    public boolean isAllowContentAccess() {
        return isAllowContentAccess;
    }

    public boolean isSavePassword() {
        return isSavePassword;
    }

    public boolean isSaveFormData() {
        return isSaveFormData;
    }

    public DKWebChromeClientCallback getChromeCallback() {
        return chromeCallback;
    }

    public DKWebViewClientCallback getClientCallback() {
        return clientCallback;
    }

    public DKWebSensorsCallback getSensorsCallback() {
        return sensorsCallback;
    }


    public DKWebViewMenuCallback getMenuCallback() {
        return menuCallback;
    }

    public boolean isUserAgentAppend() {
        return isUserAgentAppend;
    }

    public List<DKWebJsPlugin> getJsPlugins() {
        return mJsPlugins;
    }

    public DKWebDownloadListener getDownloadListener() {
        return mDownloadListener;
    }

    public static class Builder {

        private DKWebToolbarConfig toolbar;

        /**
         * webkit加载地址
         */
        private String url;
        /**
         * 下一页地址
         */
        private String nextUrl;
        /**
         * 业务代码
         */
        private DKWebCallback webCallback;
        private DKWebChromeClientCallback chromeCallback;
        private DKWebViewClientCallback clientCallback;
        private DKWebSensorsCallback sensorsCallback;
        private DKWebViewMenuCallback menuCallback;
        /**
         * js
         */
        private List<DKWebJsPlugin> mJsPlugins = new LinkedList<>();

        private DKWebDownloadListener mDownloadListener;

        /**
         * 请求头
         */
        private Map<String, String> headers;
        /**
         * UserAgent
         */
        private String userAgent = "";
        private boolean isUserAgentAppend = true;

        private boolean isJsEnabled = true;
        /**
         * 设置可以支持缩放
         */
        private boolean isSupportZoom = false;
        /**
         * 设置出现缩放工具
         */
        private boolean isBuiltInZoomControls = false;
        /**
         * 自适应屏幕
         */
        private boolean isUseWideViewPort = true;
        private boolean isLoadWithOverviewMode = true;
        /**
         * 支持通过JS打开新窗口
         */
        private boolean isJavaScriptCanOpenWindowsAutomatically = true;
        private boolean isAllowFileAccess = true;
        private boolean isAppCacheEnabled = true;
        private boolean isDatabaseEnabled = true;
        private boolean isDomStorageEnabled = true;
        private boolean isGeolocationEnabled = true;
        private boolean cacheMode = false;
        private boolean isAllowContentAccess = true;
        private boolean isSavePassword = true;
        private boolean isSaveFormData = true;

        public Builder() {
        }

        public DKWebConfig builder() {
            return new DKWebConfig(this);
        }

        public Builder setToolbar(DKWebToolbarConfig toolbar) {
            this.toolbar = toolbar;
            return this;
        }

        public Builder setUrl(String url) {
            this.url = url;
            return this;
        }

        public Builder setNextUrl(String nextUrl) {
            this.nextUrl = nextUrl;
            return this;
        }

        public Builder setWebCallback(DKWebCallback webCallback) {
            this.webCallback = webCallback;
            return this;
        }

        public Builder setChromeCallback(DKWebChromeClientCallback chromeCallback) {
            this.chromeCallback = chromeCallback;
            return this;
        }

        public Builder setClientCallback(DKWebViewClientCallback clientCallback) {
            this.clientCallback = clientCallback;
            return this;
        }

        public Builder setSensorsCallback(DKWebSensorsCallback sensorsCallback) {
            this.sensorsCallback = sensorsCallback;
            return this;
        }

        public Builder setMenuCallback(DKWebViewMenuCallback menuCallback) {
            this.menuCallback = menuCallback;
            return this;
        }

        public Builder setJsPlugins(List<DKWebJsPlugin> jsPlugins) {
            if (jsPlugins != null) {
                this.mJsPlugins.addAll(jsPlugins);
            }
            return this;
        }

        public Builder setDownloadListener(DKWebDownloadListener listener) {
            this.mDownloadListener = listener;
            return this;
        }

        public Builder setHeaders(Map<String, String> headers) {
            this.headers = headers;
            return this;
        }

        public Builder setUserAgent(String userAgent) {
            this.userAgent = userAgent;
            return this;
        }

        public Builder setUserAgentAppend(boolean userAgentAppend) {
            this.isUserAgentAppend = userAgentAppend;
            return this;
        }

        public Builder setJsEnabled(boolean jsEnabled) {
            this.isJsEnabled = jsEnabled;
            return this;
        }

        public Builder setSupportZoom(boolean supportZoom) {
            this.isSupportZoom = supportZoom;
            return this;
        }

        public Builder setBuiltInZoomControls(boolean isBuiltInZoomControls) {
            this.isBuiltInZoomControls = isBuiltInZoomControls;
            return this;
        }

        public Builder setUseWideViewPort(boolean useWideViewPort) {
            this.isUseWideViewPort = useWideViewPort;
            return this;
        }

        public Builder setLoadWithOverviewMode(boolean loadWithOverviewMode) {
            this.isLoadWithOverviewMode = loadWithOverviewMode;
            return this;
        }

        public Builder setJavaScriptCanOpenWindowsAutomatically(boolean javaScriptCanOpenWindowsAutomatically) {
            this.isJavaScriptCanOpenWindowsAutomatically = javaScriptCanOpenWindowsAutomatically;
            return this;
        }

        public Builder setAllowFileAccess(boolean allowFileAccess) {
            this.isAllowFileAccess = allowFileAccess;
            return this;
        }

        public Builder setAppCacheEnabled(boolean appCacheEnabled) {
            this.isAppCacheEnabled = appCacheEnabled;
            return this;
        }

        public Builder setDatabaseEnabled(boolean databaseEnabled) {
            this.isDatabaseEnabled = databaseEnabled;
            return this;
        }

        public Builder setDomStorageEnabled(boolean domStorageEnabled) {
            this.isDomStorageEnabled = domStorageEnabled;
            return this;
        }

        public Builder setGeolocationEnabled(boolean geolocationEnabled) {
            this.isGeolocationEnabled = geolocationEnabled;
            return this;
        }

        public Builder setCacheMode(boolean cacheMode) {
            this.cacheMode = cacheMode;
            return this;
        }

        public Builder setAllowContentAccess(boolean allowContentAccess) {
            this.isAllowContentAccess = allowContentAccess;
            return this;
        }

        public Builder setSavePassword(boolean savePassword) {
            this.isSavePassword = savePassword;
            return this;
        }

        public Builder setSaveFormData(boolean saveFormData) {
            this.isSaveFormData = saveFormData;
            return this;
        }
    }

}
